const emojiData = require('./emoji.json');

export default {
  methods: {
    emojiFormat(content) {
      return content.replace(/\[[\u4E00-\u9FA5]{1,8}\]|\[OK\]/gi, this.emoji);
    },
    emoji(res) {
      const word = res.replace(/\[|\]/gi, '');
      const index = emojiData.map(obj => obj.name).indexOf(word);
      if (index !== -1) {
        const curEnv = process.env.NODE_ENV === 'production' ? 'https://vue.learnerhub.net' : '';
        const src = `${curEnv}/static/emoji/${emojiData[index].codes}.png`;
        return `<img style="width: 20px; height: 20px; vertical-align: text-bottom;" src="${src}">`;
      }
      return res;
    },
  },
};
